package com.housekeeping.housekeeping.adManager.dao.impl;

import com.housekeeping.housekeeping.adManager.dao.CategoryDao;
import com.housekeeping.housekeeping.adManager.entity.Category;
import com.housekeeping.housekeeping.adManager.utils.DbManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class CategoryDaoImpl implements CategoryDao {
    @Override
    public int insert(Category category) throws SQLException {
        Connection connection = DbManager.getConnection();
        String sql = "insert into advertising_management(name,parent,keyword,img,create_date,description,cate_order) values(?,?,?,?,?,?,?)";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setObject(1,category.getName());
        ps.setObject(2,category.getParent());
        ps.setObject(3,category.getKeyword());
        ps.setObject(4,category.getImg());
        ps.setObject(5,category.getDate());
        ps.setObject(6,category.getDescription());
        ps.setObject(7,1);
        int i = ps.executeUpdate();
        DbManager.closeAll(connection,ps);
        return i;
    }

    @Override
    public int update(Category category) {
        return 0;
    }
}
